package com.srit.system.controller;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.srit.core.bean.Page;
import com.srit.system.bean.CodeType;
import com.srit.system.dao.CodeTypeDao;

/**
 * @author guan
 * 
 */
@Controller
public class CodeTypeController {
	@Autowired
	private CodeTypeDao codeTypeDao;

	@RequestMapping("/codeType-search")
	public String search(@ModelAttribute Page page) {
		codeTypeDao.page(page);
		return "system/codeType";
	}

	@RequestMapping("/codeType-form")
	public String form(@ModelAttribute CodeType codeType) {
		return "system/codeType";
	}

	@RequestMapping("/codeType-edit")
	public String edit(@RequestParam int id, @ModelAttribute CodeType codeType) {
		BeanUtils.copyProperties(codeTypeDao.getById(id), codeType);
		return "system/codeType";
	}

	@RequestMapping("/codeType-saveOrUpdate")
	public String saveOrUpdate(CodeType codeType) {
		if (codeType.getId() != null && codeType.getId() != 0) {
			codeTypeDao.update(codeType);
		} else {
			codeTypeDao.save(codeType);
		}
		return "forward:/codeType-search";
	}

}
